const md5 = require('md5');
module.exports = {
  async post({ req, res, config, api, db }) {
    let data = await db.user.find(req.body);
    if (data.length) {
      let token = md5(req.body.name + req.body.password);
      res.cookie('token', token);
      res.success({ token });
      let data = await db.token.find({ token });
      if (data.length) {
        console.log(token);
        db.token.updateOne({ token }, { token, user: req.body, agemax: Date.now() + 7 * 24 * 60 * 60 })
      } else {
        (new db.token({ token, user: req.body, agemax: Date.now() + 7 * 24 * 60 * 60 })).save()
      }
    } else {
      res.info()
    }
  },
};